//
//  View2ControllerViewController.m
//  book
//
//  Created by KL on 16/12/12.
//  Copyright © 2016年 huangfeng. All rights reserved.
//

#import "View2Controller.h"
#import "TextViewController.h"
@interface View2Controller()<UIPageViewControllerDataSource,UIPageViewControllerDelegate>
{
    int curpage;
}
@end

@implementation View2Controller

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.delegate = self;
    self.dataSource = self;
    curpage = 0;
    TextViewController *con = [self.storyboard instantiateViewControllerWithIdentifier:@"text"];
    con.page = curpage;
    [self setViewControllers:@[con] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
}

- (nullable UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
    if (curpage == 0) {
        return viewController;
    }
    TextViewController *con = [self.storyboard instantiateViewControllerWithIdentifier:@"text"];
    con.page = --curpage;
    return con; 
}

- (nullable UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
    TextViewController *con = [self.storyboard instantiateViewControllerWithIdentifier:@"text"];
    con.page = ++curpage;
    return con;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
